package com.zt.ztyh.admin.controller;


import com.sun.jdi.InternalException;
import com.zt.ztyh.admin.service.FileUploadService;
import com.zt.ztyh.model.common.Result;
import com.zt.ztyh.model.common.ResultCodeEnum;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InvalidResponseException;
import io.minio.errors.XmlParserException;
import jakarta.annotation.Resource;
import org.springframework.web.ErrorResponseException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.rmi.ServerException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("/admin/system")
public class FileUploadController {
    @Resource
    private FileUploadService fileUploadService;
    @PostMapping(value = "/fileUpload")
    public Result<String> fileUploadService(@RequestParam(value = "file") MultipartFile file) throws ServerException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InternalException, io.minio.errors.ServerException, InsufficientDataException, io.minio.errors.ErrorResponseException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
        String fileUrl = fileUploadService.fileUpload(file) ;
        return Result.build(fileUrl , ResultCodeEnum.SUCCESS) ;
    }
}
